﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EzDesk.Core.Model;

namespace EzDesk.Core.Interface
{
    public interface ICoreService
    {
        #region [System Globle Info - lastReview: 2011.1.5]
        Organization GetOrganizationInfo();
        void UpdateOrganizationInfo(Organization org);
        #endregion

        #region [ Users Profile Methods - lastReview: 2010.3.3]

        List<SimpleUser> GetAllUsers();
        UserProfile GetUserProfileByUserName(string userName);
        UserProfile GetUserProfileById(Guid userId);
        List<UserProfile> GetUserProfiles(Guid[] userIdCollection);
        List<UserProfile> GetUserProfiles(string memberstring);
        void UpdateUserProfile(UserProfile userProfile);
        
        UserProfile CreateEmptyUserProfile(string userName);
        void DeleteUserProfile(Guid userId);

        List<SimpleUser> GetSimpleUserInfos(Guid[] userIdCollection);
        List<SimpleUser> GetSimpleUserInfos(string memberstring);
        SimpleUser GetSimpleUserById(Guid userId);

        SimpleUser GetSimpleUserInfoByUserName(string userName);
        List<SimpleUser> GetUsersInDept(Guid deptId);
        List<SimpleUser> GetUsersInPosition(Guid posId);

        void UpdateHeadIcon(Guid userId, byte[] iconData, string imageType);
        UserHeadImage GetHeadIcon(Guid userId);

        #endregion [ Users Profile Methods - lastReview: 2010.3.3]

        #region [ Department    -   2010.1.17]
        List<Dept> GetAllDepts();
        Dept GetDeptById(Guid deptId);
        Dept CreateDept(string deptName);
        void ChangeDeptName(Guid deptId,string deptName);
        void DeleteDept(Guid deptId);
        #endregion [ Department    -   2010.1.17]

        #region [ Group & Memberstring    -   2010.10.28]
        Group CreateGroup(SimpleUser[] userIds,Group[] groupIds,string descrition,int type);
        void DeleteGroup(Guid groupId);
        void ChangeGroupDescription(Guid groupId, string description);

        List<Group> GetAllSystemGroups();
        Group GetSystemGroup(string sysGroupName);
        List<Group> GetPermissionGroups();

        Group GetGroupByName(string groupName);
        Group GetGroupById(Guid groupId);
        List<Group> GetGroups(string groupIdStrs = null);
        List<Group> GetGroups(Guid[] groupIdCollection);

        IDictionary<Guid, string> GetChildrenByMemberstring(string memberString);

        List<SimpleUser> GetAllUsersInGroup(Guid groupId);

        List<Group> GetUserInGroups(Guid userId, int groupType = -1 /* 指明用户组类型，<0则不判断  */);
        bool IsUserInGroup(Guid userId, Guid groupId);

        List<Guid> GetAllUserIdsByMemberString(string memberString);
        List<SimpleUser> GetAllUsersByMemberString(string memberString);

        void UpdateProjectGroup(Guid projectId, string projectName, string memberstring);


        #endregion [ Group    -   2010.10.28]

        #region [ Position    -   2010.1.17]
        List<Position> GetPositions();
        Position CreatePosition(string descrition, int priority = -1);
        void ChangePositionPriority(Guid posId,int priority);
        void ChangePositionDescription(Guid posId, string description);
        void DeletePosition(Guid positionId);
        #endregion [ Position    -   2010.1.17]

        #region [ Feed Common    -   2010.3.3 ]

        void UpdateFeedStatus(List<FeedStatus> feedStatus, string memeberString);

        void DeleteFeed(Guid feedId, int type);
        void UpdateFeedData(Guid feedId, string newFeedData);
        void UpdateFeedData(string feedIdStrs, string newFeedData);
        void UpdateFeedRecipients(Guid feedId, string memerstring);
        void UpdateUserGroups(List<Guid> groupIdList, Guid userId);
        
        /// <summary>
        /// 取一段时间中的feeds，如果不指定时间，那么就按照时间顺序取一定条数
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="maxCount">取出来的最大条数</param>
        /// <param name="includeNotification">是否要把所有的notification取出来，如果为true，那么macCount不计算notification，如果为false，则不指定feed类型</param>
        /// <param name="isRead"></param>
        /// <param name="isAvaiable"></param>
        /// <param name="isMark"></param>
        /// <returns></returns>
        List<Feed> GetFeeds(Guid userId, DateTime? from, DateTime? to, int maxCount, bool includeNotification, bool? isRead, bool? isAvailable, bool? isMark);

        List<Group> GetUserPermissionGroups(Guid userId);

        // 使用templateName发送Feed
        Guid SendFeed(
            string templateName, /* 使用的模板名称 */
            string feedData, /* Feed数据 */
            string memberString, /* 接收者 */
            Guid? senderId, /* 发送者UserID 可空 */
            string ignoreUsers, /* 这条消息忽略发射的人 */ 
            bool isAvailable,    /* 该feed是否有效 */
            bool isDisplayInMainPanel
            );

        void UpdatePersonalFeedData(Guid feedId, string memberstring, string feedDataEx);
        void UpdatePersonalFeedType(Guid feedId, string memberstring, string feedTypeStr);
        
        string GetPersonalFeedData(Guid userId, Guid feedId);
        // 一次拿一个user的多个feedId
        Dictionary<Guid, string> GetPersonalFeedsData(Guid userId, List<Guid> feedIds);

        // 设置Feed发送记录
        void SetFeedRecord(Guid identity, string templateName, string memberstring, Guid feedId, string ignoreUsers);
        // 获取Feed发送记录
        string GetFeedRecord(Guid identity, string templateName, string userIds);
        #endregion

        #region [ FeedTemplate    -   2010.3.17]
        FeedTemplate CreateFeedTemplate(string titleTemplate,string bodyTemplate,int type);
        void DeleteFeedTemplate(Guid templateId);
        FeedTemplate GetFeedTemplateById(Guid templateId);
        List<FeedTemplate> GetFeedTemplate(string templateName = null);
        #endregion [ FeedTemplate    -   2010.1.17]

        #region [ Permission   -  2010.9.17 ]
        /// <summary>
        /// 在系统中注册一个权限
        /// </summary>
        /// <param name="permission"></param>
        void RegisterPermission(Permission permission);

        /// <summary>
        /// 根据AppId获得权限列表
        /// </summary>
        /// <param name="AppId">权限列表的AppName，为空则获得Core权限</param>
        /// <returns></returns>
        List<Permission> GetPermissionList();

        /// <summary>
        /// 根据一个 用户权限字符串 获得一个权限
        /// </summary>
        /// <param name="permissionStr"></param>
        /// <returns></returns>
        Permission GetPermission(string permissionStr);

        /// <summary>
        /// 设置某个用户组的权限
        /// </summary>
        /// <param name="permissionStr">用户权限字符串</param>
        /// <param name="userId"></param>
        /// <param name="hasPermission"></param>
        void SetGroupPermission(string permissionStr, Guid groupId, bool hasPermission);

        /// <summary>
        /// 用户是否拥有权限
        /// </summary>
        /// <param name="permissionStr">用户权限字符串</param>
        /// <param name="userId">用户Id</param>
        /// <returns></returns>
        bool UserHasPermission(string permissionStr, Guid userId);


        /// <summary>
        /// 用户组是否拥有权限
        /// </summary>
        /// <param name="permissionStr">用户权限字符串</param>
        /// <param name="userId">用户组Id</param>
        /// <returns></returns>
        bool GroupHasPermission(string permissionStr, Guid groupId);


        #endregion






        void RemovePosition(Guid positionId);
        void SaveDeviceToken(Guid userId, string deviceToken);
        string GetDeviceToken(Guid userId);
        void ClearDeviceToken(Guid userId);
    }
}
